import tempfile

# 创建一个临时文件并在关闭时自动删除它
with tempfile.TemporaryFile(mode='w+') as tf:
    tf.write('Hello world!')
    tf.seek(0)
    content = tf.read()
    print(content)  # 输出：Hello world!